package com.arron.algorithm.leetcodetop100.二叉树;

import com.arron.algorithm.tree.TreeNode;

/**
 * 543. 二叉树的直径
 */
public class TreeDiameter {
    int  max = 0;

    public int diameterOfBinaryTree(TreeNode root) {
        return diameter(root);

    }


    public int diameter(TreeNode root){
        if (root == null){
            return 0;
        }
        int left =  diameter(root.left);
        int right = diameter(root.right);
        max = Math.max(max,left+right);
        return 1+Math.max(left,right);
    }


}
